<%-- 
    Document   : role
    Created on : 2016-7-1, 14:13:07
    Author     : 52461
--%>

<%@page import="com.cxhd.lis.DataCache"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link2.jsp"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--         <link rel="stylesheet" href="${base}/css/nprogress.css"/>

<link rel="stylesheet" href="${base}/css/app.css"/>
<link rel="stylesheet" href="${base}/css/font-awesome.css"/>
<link rel="stylesheet" href="${base}/css/material-kit.css"/>
<link rel="stylesheet" href="${base}/js/angular/angular-ui-select/select.min.css"/>
<link rel="stylesheet" href="${base}/css/materialdesignicons.min.css"/>
<link rel="stylesheet" href="${base}/css/layui.css"/>
<script type="text/javascript" src="${base}/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${base}/js/jquery.cxhd.js"></script>
<script type="text/javascript" src="${base}/js/thenBy.js"></script>
<script type="text/javascript" src="${base}/js/layui.all.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular.min.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular-translate/angular-translate.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular-sanitize/angular-sanitize.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular-ui-utils/ui-utils.js"></script>
<script type="text/javascript" src="${base}/js/angular/angular-ui-select/select.min.js"></script>
<script type="text/javascript" src="${base}/js/jquery.ui.combogrid-1.6.3.js"></script>
<script type="text/javascript" src="${base}/js/bootstrap.js"></script>
<script type="text/javascript" src="${base}/js/material.min.js"></script>
<script type="text/javascript" src="${base}/js/nprogress.js"></script>

<script type="text/javascript" src="${base}/js/angular-base.js"></script>-->
        <script type="text/javascript" src="${base}/js/highcharts/highcharts.js" ></script>
        <script type="text/javascript" src="${base}/js/mychartoption.js" ></script>
        <title>JSP Page</title>
        <style>
            * { margin:0; padding:0;}
            body { margin:0; padding:0;  font-family:"微软雅黑";}
            table td { padding:1px 1px;}
            .title { font-size:24px; text-align:center; width:40%;}
            .check_info th { border-bottom:1px #666 solid; padding-bottom:5px;}
            /*.check_info td,th{ padding-left:20px;}*/
            .hx{ border-right:  1px #666 solid}
             .s-warning{
        color:red;
    }
    .s-danger{
        color:blue;
    }      
    .s_warning{
        color:red;
    }
    .s_danger{
        color:blue;
    }    
    .warning{
        color:red;
    }
    .danger{
        color:blue;
    }
        </style>
    </head>
    <body  ng-app="jyjgManager" ng-controller="jyjgCtrl" >
        <table width="1000px" style=" margin:0 auto;font-size:{{fontSize}}" cellpadding="0" cellspacing="0">
            <tr>
                <td colspan="2">
                    <div style="text-align: center">
                        <h4 style="font-weight: bold;font-size: 24px;" ng-bind="reportName"></h4>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2"> 
                    <table cellpadding="0" cellspacing="0" width="100%" style=" border-bottom:1px #666 solid;font-size:{{fontSize}}">
                         <tr>
                            <td  style="font-weight: bold;" align="right" width="80px">姓名：</td>
                            <td style="font-weight: bold;" contenteditable="true" align="left" width="100px">{{info.PATIENTNAME}}</td>
                            <td align="right">病历号：</td>
                            <td contenteditable="true" align="left" width="100px">{{info.PATIENTID}}</td>
                            <td align="right">科室：</td>
                            <td contenteditable="true" align="left" width="100px">{{info.SECTION}}</td>
                            <td align="right">样本号：</td>
                            <td contenteditable="true" align="left" width="120px">{{sampleNo}}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;" align="right">性别：</td>
                            <td style="font-weight: bold;" contenteditable="true" align="left">{{info.SEX}}</td>
<!--                            <td align="right">病房号：</td>
                            <td contenteditable="true" align="left"></td>-->
                            <td align="right">床号：</td>
                            <td contenteditable="true" align="left">{{info.BED_NO}}</td>
                            <td align="right">送检医生：</td>
                            <td contenteditable="true" align="left">{{info.SJYS}}</td>
                            <td align="right">临床诊断：</td>
                            <td contenteditable="true" align="left">{{info.DIAGNOSTIC}}</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;" align="right">年龄：</td>
                            <td style="font-weight: bold;" contenteditable="true" align="left">{{info.AGE}}</td>
                            <td align="right">送检时间：</td>
                            <td  >{{info.CUSTOM1}}</td>
<!--                            <td contenteditable="true" align="left">{{info.BED_NO}}</td>
-->                            <td align="right">机器型号：</td>
                            <td contenteditable="true" align="left">{{results[0].DEVICEID}}</td>
                            <td align="right">备注：</td>
                            <td contenteditable="true" align="left">{{info.CUSTIOM2}}</td>
                             <!--<td contenteditable="true" align="left">{{info.EXAMINAIM}}</td>-->
                        </tr>
                    </table>
                </td>
            </tr>
            <tr style="border-bottom:1px #666 solid;height:430px;">
                <td colspan="2" valign="top">
                    <table width="100%">
                        <tr>
                            <td valign="top" width="50%"  style=" padding-right:0;border-right: 1px #000 solid">
                                <table cellpadding="0" cellspacing="0" width="100%" class="check_info" style="font-size:{{fontSize}}; border-bottom: 1px #000 solid" >
                                    <thead>
                                        <tr>
                                            <th align="left">项目简称</th>
                                            <th align="left">项目名称</th>

                                            <th></th>
                                            <th align="left">结果</th>

                                            <th align="left">单位</th>
                                            <th align="left">参考范围</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="le in left| filter:{RESULTFLAG:'0'}"  ng-class="{true: 's-danger', false: 's-warning'}[le.isActive]">
                                            <!--<td>{{$index+1}}</td>-->
                                            <td>{{le.TESTID}}</td>
                                            <td>{{le.CHINESENAME}}</td>
                                            <td>{{le.HL_STATUS}}</td>
                                            <td>{{le.TESTRESULT}}</td>

                                            <td>{{le.UNIT}}</td>
                                            <td ng-class="{
                                            true: 'hx', false: 'inactive'}
                                                [isActive]">{{le.fanwei}}</td>
                                        </tr>
                                    </tbody>
                                </table>
                                <table  cellpadding="0" cellspacing="0" width="100%" style="font-size:{{fontSize}}">
                                    <tr style="border-bottom: 1px #000 solid">
                                        <td align="left">
                                            尿理学指标
                                        </td>
                                        <td>
                                                颜色:{{results[25].TESTRESULT}}</br>
                                                浊度:{{results[26].TESTRESULT}}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="left">
                                            尿红细胞形态学指标
                                        </td>
                                        <td>
                                                正常红细胞（%）:{{results[27].TESTRESULT}}（%）</br>
                                                异常红细胞（%）:{{results[28].TESTRESULT}}（%）
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td valign="top" style="padding-left:0; margin:0;display:none" id="fenye">
                                <table cellpadding="0" cellspacing="0" width="100%" class="check_info" style="margin-left: 5px;font-size:{{fontSize}}">
                                    <thead>
                                        <tr>
                                            <th align="left">项目简称</th>
                                            <th align="left">项目名称</th>
                                            <th></th>
                                            <th align="left">结果</th>

                                            <th align="left">单位</th>
                                            <th align="left">参考范围</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="ri in right| filter:{RESULTFLAG:'0'}"  ng-class="{true: 's-danger', false: 's-warning'}[ri.isActive]">
                                            <!--<td>{{$index+15}}</td>-->
                                            <td>{{ri.TESTID}}</td>
                                            <td>{{ri.CHINESENAME}}</td>
                                            <td>{{ri.HL_STATUS}}</td>
                                            <td>{{ri.TESTRESULT}}</td>

                                            <td>{{ri.UNIT}}</td>
                                            <td>{{ri.fanwei}}</td>
                                        </tr>
                                    </tbody>
                                </table>



                            </td>
                        </tr>
                    </table>



                    <div ng-show="chart" style="position:relative; bottom: -20px;margin-top: -30px; ">

                         <div ng-show="sh_baso" id="baso"  style="float: left;width:170px;height: 170px;">></div>
                         <div ng-show="sh_diff" id="diff"  style="float: left;width:170px;height: 170px;"></div>
                      
                         <div ng-show="sh_wbc" id="wbc"  style="float: left;width:230px;height: 170px;"></div>
                        <div ng-show="sh_rbc" id="rbc"  style="float: left;width:230px;height: 170px;"></div>
                        <div ng-show="sh_plt" id="plt"  style="float: left;width:230px;height: 170px;"></div>
                       
                        
                        <div style="clear: both"></div>
                    </div>

                    <div ng-show="zftchart">
                        <div ng-show="sh_wbc" style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                            <div>WBC</div>
                            <img ng-src="{{WBC}}" height="{{imageHeight}}" />
                        </div>
                        
                        <div ng-show="sh_rbc"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                            <div>RBC</div>
                            <img ng-src="{{RBC}}" height="{{imageHeight}}" />
                        </div>
                         <div ng-show="sh_diff"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                            <div>DIFF</div>
                            <img ng-src="{{DIFF}}" height="{{imageHeight}}"/>
                        </div>
                         <div ng-show="sh_baso"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                            <div>BASO</div>
                            <img ng-src="{{BASO}}" height="{{imageHeight}}"/>
                        </div>

                        <div ng-show="sh_plt"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                            <div>PLT</div>
                            <img ng-src="{{PLT}}" height="{{imageHeight}}" />
                        </div>
                         <div  ng-show="sh_sret"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                                            <div>SRET</div>
                                            <img ng-src="{{SRET}}" height="{{imageHeight}}" />
                             </div>
                        <div  ng-show="sh_swdf"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                                            <div>SWDF</div>
                                            <img ng-src="{{SWDF}}" height="{{imageHeight}}"/>
                            </div>
                        <div  ng-show="sh_swnr"  style="float: left;width:{{imageWidth}};height: 140px;margin-left: 10px;">
                                     <div>SWNR</div>
                                    <img ng-src="{{SWNR}}" height="{{imageHeight}}" />
                            </div>
                         <div style="clear: both"></div>
                    </div>
                    <div ng-show="image_more">
                        <div ng-repeat="image in moreImage" style="float: left;margin-left: 10px;">
                                          <img height="110px" ng-src="{{image}}" />
                            </div>
                        <div style="clear: both"></div>
                        </div>
                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <table style="font-size:{{fontSize}}" width="100%">
                         <tr>
                            
                            <td align="left" width="80px">报告日期：</td>
                            <td contenteditable="true" align="left" width="260px">{{date}}</td>
<!--                             <td align="right" width="120px">送检时间：</td>
                            <td   contenteditable="true" align="left" width="300px">{{info.CUSTOM1}}</td>-->
                            <td align="left" width="200px">检验医生<span style="margin-left: 10px;margin-right: 10px;">:</span>{{info.JYYS}}</td>
                            <!--                            
                                                        <td contenteditable="true" align="left" width="80px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left"width="100px" ></td>-->
                            <td  colspan="" align="right" width="120px">审核人：</td>
                            <td   contenteditable="true" align="left" width="100px">
                               <span ng-hide="sign">{{info.CHECKOPERATOR}}</span>
                                <img style="position: fixed" height="40px" ng-show="sign" ng-src="{{sign}}">
                            </td>
                        </tr>
                        <tr>
                            
                            <td colspan="4" align="left" width="120px">注：此结果仅对本份检验标本负责 </td>
                            <!--<td   contenteditable="true" align="left" width="300px"></td>-->
                           
                            <td align="right" width="200px"></td>
                            <!--                            <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="100px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="100px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="120px"></td>-->
<!--                            <td align="right" width="120px">报告日期：</td>
                            <td contenteditable="true" align="left" width="260px">{{date}}</td>-->
                        </tr>
                    </table>
                </td>

            </tr>

        </table>

    </body>
</html>
<script>
    angular.module("jyjgManager", ['baseModule'])
    .controller("jyjgCtrl", function($scope,base) {
        var WBC = [];
        var RBC = [];
        var PLT = [];
         var BASO = [];
          var DIFF = [];
          var SRET = [];
            var SWDF = [];
                var SWNR = [];
        $scope.config = {};
        $scope.fontSize = "16px";
        $scope.imageWidth = "230px";
        $scope.imageHeight="120px";
        $scope.reportName = "<%=DataCache.getIntance().getConfig().get("hospitalName")%>检验报告单";
        console.log('<%=DataCache.getIntance().getConfig().get("hospitalName")%>');
        if (localStorage.results) {
            $scope.results = JSON.parse(localStorage.results);
            var s=0;
            for( i in  $scope.results){
                var test_id = $scope.results[i].TESTID;
                if (test_id && test_id.indexOf('image') > -1) {
                    s++;
                    }
            }
            if(s>4){
                  $scope.imageWidth = "180px";
                  $scope.imageHeight="120px";
            }
           // console.table($scope.results);
        }
        if (localStorage.info) {

            $scope.info = JSON.parse(localStorage.info);
        }
        if (localStorage.reprotConfig) {
            $scope.config = JSON.parse(localStorage.reprotConfig);
            console.log($scope.config);
            if ($scope.config.reportName != "") {
                $scope.reportName = $scope.config.reportName;
            }
            if ($scope.config.fontSize != "") {
                $scope.fontSize = $scope.config.fontSize;
            }
            //console.log($scope.config.reportName + "  " + $scope.fontSize);
        }


         var checkChart = function () {
                    console.log(typeof DIFF);
                    console.log(DIFF);
                    $scope.WBC = "";
                    $scope.RBC = "";
                    $scope.PLT = "";
                    $scope.BASO = "";
                    $scope.DIFF = "";
                     $scope.SWNR = "";
                    $scope.SWDF = "";
                    $scope.SRET = "";
                    if (typeof RBC == "string") {
                        $scope.WBC = "data:image/jpg;base64," + WBC;
                        $scope.RBC = "data:image/jpg;base64," + RBC;
                        $scope.PLT = "data:image/jpg;base64," + PLT;
                        $scope.BASO = "data:image/jpg;base64," + BASO;
                        $scope.DIFF = "data:image/jpg;base64," + DIFF;
                        $scope.SWNR = "data:image/jpg;base64," + SWNR;
                        $scope.SWDF = "data:image/jpg;base64," + SWDF;
                        $scope.SRET = "data:image/jpg;base64," + SRET;
                        $scope.zftchart = true;


                    } else {
                        var NEWWBC = [], NEWRBC = [], NEWPLT = [];
                        if (RBC.length > 0) {
                            var WBCindexs = [];
                            for (var i in WBC) {
                               
                                if (WBC.length < 500) {
                                    WBCindexs.push(i);
                                    NEWWBC.push(parseFloat(WBC[i]));
                                }
                            }
                            var RBCindexs = [];
                            for (var i in RBC) {
                                RBCindexs.push(i);
                                NEWRBC.push(parseFloat(RBC[i]));
                            }
                            var PLTindexs = [];
                            for (var i in PLT) {
                                PLTindexs.push(i);
                                NEWPLT.push(parseFloat(PLT[i]));
                            }
//                        var WBCChart = echarts.init(document.getElementById('wbc'));
//                        var RBCChart = echarts.init(document.getElementById('rbc'));
//                        var PLTChart = echarts.init(document.getElementById('plt'));
//
//                        WBCChart.setOption(getChart("WBC", WBCindexs, WBC));
//                        RBCChart.setOption(getChart("RBC", RBCindexs, RBC));
//                        PLTChart.setOption(getChart("PLT", PLTindexs, PLT));


                        }
                          $scope.chart = true;
                        var baso = false;
                        for (var i in $scope.results) {
                            if ($scope.results[i].TESTID == "BASOR") {
                                baso = true;
                                break;
                            }
                        }
                        if (baso) {
                            $('#wbc').highcharts(getChart2("WBC/BASO", WBCindexs, NEWWBC));
                        } else {
                            //console.log(NEWWBC);
                            if (WBC.length > 500) {
                                $('#wbc').highcharts(getChart3("WBC", WBC));
                            } else {
                                $('#wbc').highcharts(getChart2("WBC", WBCindexs, NEWWBC));
                            }
                        }
                        //console.log(BASO);
                        if(BASO.length>0){
                             $('#baso').highcharts(getChart3("BASO", BASO));
                        }
                        if (DIFF.length > 0) {
                            $('#diff').highcharts(getChart3("DIFF", DIFF));
                        }

                        $('#rbc').highcharts(getChart2("RBC", RBCindexs, NEWRBC));
                        $('#plt').highcharts(getChart2("PLT", PLTindexs, NEWPLT,"PLT"));
                    }

                }

        $scope.sampleNo = localStorage.sampleNo;
        $scope.date = localStorage.date;
        $scope.left = [];
        $scope.right = [];
        $scope.isActive = false;
        $scope.copyResult = angular.copy($scope.results);
           $scope.moreImage=[];
        //console.table($scope.results);
        for (var i = 0; i < $scope.copyResult.length; i++) {
              if ($scope.copyResult[i].RESULTFLAG == "4") {
                $scope.moreImage.push("data:image/jpg;base64," + $scope.copyResult[i].TESTRESULT);
                }
            if ($scope.copyResult[i].TESTID == 'image#WBC') {
                 $scope.sh_wbc=true;
                if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     WBC = $scope.copyResult[i].TESTRESULT.toString();
                    // console.log(WBC);
                }
                 else if ($scope.copyResult[i].RESULTFLAG == '3') {
                     var wbcs = $scope.copyResult[i].TESTRESULT.split(",");
                          for (s in wbcs) {
                                WBC.push([parseFloat($.trim(wbcs[s]).split(" ")[0]), parseFloat($.trim(wbcs[s]).split(" ")[1])]);
                           }
                  }
                else{
                    WBC = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
                // console.log(WBC+"--------------------");
                // $scope.results.splice(i,1);
                // console.log(WBC);
            } else if ($scope.copyResult[i].TESTID.toString() == 'image#RBC') {
                 $scope.sh_rbc=true;
               if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     RBC = $scope.copyResult[i].TESTRESULT.toString();
                }
               
                
                else{
                    RBC = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
               // RBC = $scope.copyResult[i].TESTRESULT.split(" ");
                //  $scope.results.splice(i,1);
            } else if ($scope.copyResult[i].TESTID == 'image#PLT') {
                     $scope.sh_plt=true;
                 if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     PLT = $scope.copyResult[i].TESTRESULT.toString();
                }else{
                    PLT = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
               
                //  $scope.results.splice(i,1);
            }
             else if ($scope.copyResult[i].TESTID == 'image#DIFF') {
                     $scope.sh_diff=true;
                 if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     DIFF = $scope.copyResult[i].TESTRESULT.toString();
                }
               else if ($scope.copyResult[i].RESULTFLAG == '3') {
                  var diffs = $scope.copyResult[i].TESTRESULT.split(",");
                       for (s in diffs) {
                             DIFF.push([parseFloat($.trim(diffs[s]).split(" ")[0]), parseFloat($.trim(diffs[s]).split(" ")[1])]);
                            }
                        }
                else{
                    DIFF = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
               
                //  $scope.results.splice(i,1);
            }
            else if ($scope.copyResult[i].TESTID == 'image#BASO') {
                 $scope.sh_baso=true;
                 if ($scope.copyResult[i].RESULTFLAG == '3') {
                  var basos = $scope.copyResult[i].TESTRESULT.split(",");
                       for (s in basos) {
                             BASO.push([parseFloat($.trim(basos[s]).split(" ")[0]), parseFloat($.trim(basos[s]).split(" ")[1])]);
                            }
                        }
                        else if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     BASO = $scope.copyResult[i].TESTRESULT.toString();
                }

                }
              else if ($scope.copyResult[i].TESTID == 'image#SWDF') {
                    $scope.sh_swdf = true;
                    if ($scope.copyResult[i].RESULTFLAG == '2') {
                          SWDF = $scope.copyResult[i].TESTRESULT;
                        }

                    } else if ($scope.copyResult[i].TESTID == 'image#SWNR') {
                       $scope.sh_swnr = true;
                         if ($scope.copyResult[i].RESULTFLAG == '2') {
                            SWNR = $scope.copyResult[i].TESTRESULT;
                        }

                    } else if ($scope.copyResult[i].TESTID == 'image#SRET') {
                            $scope.sh_sret = true;
                        if ($scope.copyResult[i].RESULTFLAG == '2') {
                            SRET = $scope.copyResult[i].TESTRESULT;
                        }

                    }
        }
        var newResult=[];
        for (var i = 0; i < $scope.results.length; i++) {

            if ($scope.results[i].TESTID.indexOf('image')<0) {
               newResult.push($scope.results[i]);
            }
        }
        $scope.results =newResult;
        console.log($scope.results);

        if ($scope.results.length > 14) {
//            for (var i = 0; i < Math.ceil($scope.results.length / 2); i++) {
//                var l = $scope.results[i];
//                $scope.left.push(l);
//            }
//            //console.log(Math.ceil($scope.results.length / 2)+'-------------------------')
//            //console.table($scope.results);
//            for (var j = Math.ceil($scope.results.length / 2); j < $scope.results.length; j++) {
//                var r = $scope.results[j];
//                $scope.right.push(r);
//            }
            $scope.left = $scope.results.slice(0,11);
            $scope.right = $scope.results.slice(11,25);
            console.log($scope.left);
            console.log($scope.right);
            $("#fenye").show();
            $(".check_info").width("50%");
            $("#hh").addClass("hx");
            $scope.isActive = true;
        } else {
            for (var i = 0; i < $scope.results.length; i++) {
                var l = $scope.results[i];
                $scope.left.push(l);
            }
        }
        if ($scope.moreImage.length > 0) {
                console.log($scope.moreImage.length);
                $scope.image_more = true;
           } else {
                    checkChart();
                   }
       //获取审核医生签名
        base.post("host/getSign",{name:$scope.info.CHECKOPERATOR}).get(function(data){
            if(data!='false'){
                $scope.sign = data;
            }
              setTimeout(function() {
                window.print();
                window.close();
               }, 1000)
        })
    })

</script>
